package com.ruoyi.operation.order.total.controller;

import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.operation.order.depot.domain.Depot;
import com.ruoyi.operation.order.enter.domain.EnterForm;
import com.ruoyi.operation.order.enter.service.IEnterFormService;
import com.ruoyi.operation.order.tablestatis.domain.TableStatis;
import com.ruoyi.operation.order.total.domain.Total;
import com.ruoyi.operation.order.total.mapper.ITotalMapper;
import com.ruoyi.operation.order.total.service.ITotalService;
import com.ruoyi.project.system.dept.domain.Dept;
import com.ruoyi.project.system.dept.service.IDeptService;
import com.ruoyi.project.system.role.service.IRoleService;
import com.ruoyi.project.system.user.service.IUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @Author king
 * @create 2019/4/16 20:46
 */
@RequestMapping(value = "/total/total")
@Controller
public class TotalController extends BaseController {

    // 定义一个跳转到页面的路径
    private String prefix = "order/total/";
    @Autowired
    private IRoleService iRoleService;
    @Autowired
    private IUserService iUserService;
    @Autowired
    private ITotalService totalService;
    @Autowired
    private IDeptService iDeptService;

    /**
     * 跳转到分析统计的页面
     * @return
     */
    @GetMapping()
    @RequiresPermissions(value = "total:total:total")
    String total(){
        return prefix + "total";
    }

    @RequestMapping(value = "/list")
    @RequiresPermissions(value = "total:total:total")
    @ResponseBody
    public TableDataInfo allEnertForm(Total total){

        // 获取当前登陆人的id
        String getUserId = ShiroUtils.getLoginId();
        // 更具当前登陆人获取roleId
        List<String> getRoleId = iRoleService.getRoleId(getUserId);
        for (String s : getRoleId){
            if (s.equals("1") || s.equals("5")){
                // 此时是超级管理员和鹰之队的管理员
                total.setUserName("");
            }else{
                total.setUserName(getUserId);
            }
        }

//        else if(getRoleId.equals("3")){
//            enterForm.setType("2");
//            // 根据id获取对应的部门id
//            String getDeptId = iUserService.getDeptId(getUserId);
//            enterForm.setDeptId(getDeptId);
//        } else if(getRoleId.equals("4")){
//            // 此时是登陆人
//            enterForm.setType("3");
//            enterForm.setCreateBy(getUserId);
//        }
        startPage();
        List<Total> totalList = totalService.total(total);
        return getDataTable(totalList);

    }

    /**
     * 导出订单信息
     * @param total
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping(value = "/exportExcel")
    @RequiresPermissions(value = "total:total:exportExcel" )
    public void exportExcel(Total total, HttpServletRequest request, HttpServletResponse response) throws Exception{
        totalService.exportTotal(total,request,response);
    }


    /**
     * 查询所有的平台
     * @return
     */
    @RequestMapping(value = "/allDeptT")
    @ResponseBody
    public List<Dept> allDeptT(){
        return iDeptService.allDeptList();
    }


}
